using System.Collections;
using UnityEngine;

public class PlayAudioWithDelay : MonoBehaviour
{
	[SerializeField]
	private AudioSource _audio;

	[SerializeField]
	private float _delay = 1f;

	private void OnEnable()
	{
		StartCoroutine(PlaySound());
	}

	private void OnDisable()
	{
		StopCoroutine(PlaySound());
	}

	private IEnumerator PlaySound()
	{
		while (true)
		{
			yield return new WaitForSeconds(_delay);
			if (_audio != null)
			{
				_audio.Play();
			}
		}
	}
}
